<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>05_JS流程控制</title>
</head>
<body>
<script>
    let username = '';
    if(!username){
        alert('用户名不能为空');
    }else{
        alert('欢迎'+ username + '登录');
    }

    let gender = 10;
    switch(gender){
        case 1:
            console.log('男');
            break;
        case 2:
            console.log('女');
            break;
        default:
            console.log('未知');
    }

    let name=['张三','李四','王五'];
    for (var i =0; i<name.length; i++){
        console.log(name[i])
    }
    //如果用var定义循环变量i，那么i会一直存在，循环结束后，i的值为name.length
    //如果用let定义循环变量i，那么i只在循环中存在，循环结束后，i不存在
    console.log(i);
    console.log('---------------------')

    for(let n of name){
        console.log(n);
    }


</script>
</body>
</html>